<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" id="userForm" lay-filter="userForm">
    <input type="hidden" name="id">
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="loginName" id="loginName" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
                <tip>填写自己管理账号的名称。</tip>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" placeholder="请输入密码" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">昵称</label>
            <div class="layui-input-block">
                <input type="text" name="name" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">QQ</label>
            <div class="layui-input-block">
                <input type="text" name="qq" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">手机</label>
            <div class="layui-input-block">
                <input type="number" name="phone" placeholder="请输入手机" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="email" name="email" placeholder="请输入邮箱" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="saveBtn">保存</button>
            </div>
        </div>
    </div>
</form>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        // 本身json str
        var jsonStr = window.rowData;
        // 把json str -> js Object
        var data = JSON.parse(jsonStr);

        // var data2 = {
        //     'loginName':'admin'
        // }

        // window Object // 并未定义 存在， js内置的一些对象
        // data.constructor 携带的 constructor Object 来自于 user.html
        // 当前的 Object 是 user-edit.html 页面的
        // user.html  open ->  user-edit.html  所以，user-edit.html 父窗口 是 user.html   parent

        // 等于 -> 对象必须在当前这个页面取构建  数据转换

        // console.log(data);
        // console.log(data.constructor);
        // console.log(data.constructor === Object);
        // console.log(data.constructor === parent.Object);

        // 猜想这里有问题
        form.val("userForm",data);

        // form.val("userForm",{
        //     'id': data.id,
        //     'loginName': data.loginName,
        //     'name': data.name,
        //     'phone': data.phone,
        //     'email': data.email,
        //     'qq': data.qq,
        // });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.post('../../user/update',data.field,function(data){
                layer.msg('修改成功');
                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);

                // 刷新表格数据
                parent.layui.table.reload('currentTableId', {
                    page: {
                        curr: 1
                    }
                }, 'data');

            },'json');
            return false;
        });

    });
</script>
</body>
</html>